package cn.kgc.ybis.service.impl;

import cn.kgc.ybis.mapper.TeacherMapper;
import cn.kgc.ybis.pojo.Teacher;
import cn.kgc.ybis.pojo.TeacherExample;
import cn.kgc.ybis.service.TeacherService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class TeacherServiceImpl implements TeacherService {
    @Resource
    TeacherMapper teacherMapper;

    @Override
    public PageInfo<Teacher> select(Integer pageNum, Integer pageSize, Integer keyword) {
        PageHelper.startPage(pageNum, 3);
        TeacherExample example = new TeacherExample();
        TeacherExample.Criteria criteria = example.createCriteria();
        List<Teacher> teachers = teacherMapper.selectByExample(example);
        PageInfo<Teacher> pageInfo = new PageInfo<>(teachers);
        PageHelper.startPage(pageNum, 3);
        return pageInfo;
    }

    @Override
    public void Add(Teacher teacher) {

        teacherMapper.insert(teacher);
    }

    @Override
    public Teacher toupdate(Integer id) {
        return teacherMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Teacher teacher) {
        teacherMapper.updateByPrimaryKeySelective(teacher);
    }

    @Override
    public int delete(Integer id) {
        return teacherMapper.deleteByPrimaryKey(id);
    }
}
